#include "openmove_Prefix.h"
#include "SkeletalAnimationFrameListener.h"

SkeletalAnimationFrameListener :: SkeletalAnimationFrameListener(AnimationState * pState, EAnimationSpeed Speed) : m_pState(pState), m_AnimationSpeed(Speed)
{
}

bool SkeletalAnimationFrameListener :: frameStarted(const FrameEvent& evt)
{
	Real Speed = evt.timeSinceLastFrame;
	switch (m_AnimationSpeed)
	{
		case(e_SpeedPause):
		{
			Speed = 0;
			break;
		}
		case(e_SpeedHalf):
		{
			Speed = evt.timeSinceLastFrame / 2;
			break;
		}
		case(e_SpeedNormal):
		{
			Speed = evt.timeSinceLastFrame;
			break;
		}
		case(e_SpeedX2):
		{
			Speed = evt.timeSinceLastFrame * 2;
			break;
		}
		case(e_SpeedX4):
		{
			Speed = evt.timeSinceLastFrame * 4;
			break;
		}
	}

	m_pState->addTime(Speed);

    // Call default
    return FrameListener::frameStarted(evt);
}

void SkeletalAnimationFrameListener :: keyClicked(KeyEvent * pE)
{
}

void SkeletalAnimationFrameListener :: keyPressed(KeyEvent * pE)
{
}

void SkeletalAnimationFrameListener :: keyReleased(KeyEvent * pE)
{
	int CurSpeed = m_AnimationSpeed;

	if (KC_LEFT == pE->getKey())
	{
		CurSpeed -= 1;
	}
	if (KC_RIGHT == pE->getKey())
	{
		CurSpeed += 1;
	}
	CurSpeed = std::min(CurSpeed, (int)e_SpeedMax - 1);
	CurSpeed = std::max(CurSpeed, 0);

	m_AnimationSpeed = (EAnimationSpeed)CurSpeed;
}
